<template>
  <div class="flex flexColumn flex1">
    <div class="title">
      <span>首页 &gt;管理员信息</span>
    </div>
    <div class="main flex flexColumn">
      <div class="main-title">管理员信息</div>
      <el-card class="box-card">
        <div class="text item flex">
          <p>管理员ID:</p>
          {{ obj.id }}
        </div>
        <div class="text item flex">
          <p>账号:</p>
          {{ obj.account }}
        </div>
        <div class="text item flex">
          <p>用户组:</p>
          {{ obj.userGroup }}
        </div>
        <div class="text item flex">
          <p>创建时间:</p>
          {{ obj.ctime }}
        </div>
        <div class="text item flex">
          <p>管理员头像:</p>
          <el-upload
            class="avatar-uploader"
            :on-success="handleAvatarSuccess"
            :data="{ id: myid }"
            action="http://127.0.0.1:5000/users/avatar_upload"
            :show-file-list="false"
          >
            <img v-if="obj.imgUrl" :src="obj.imgUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { accountinfo } from "@/apis/user.js";
import { getYYYYMMDDHHMMSS } from "@/utlis/utils";
export default {
  data() {
    return {
      id: localStorage.id,
      obj: {},
    };
  },
  computed: {
    myid() {
      return localStorage.id;
    },
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.obj.imgUrl = URL.createObjectURL(file.raw);
      this.$bus.emit("avatarUploadSuccess", res.imgUrl);
    },
  },
  created() {
    accountinfo({ id: this.id }).then((res) => {
      res.data.accountInfo.ctime = getYYYYMMDDHHMMSS(
        res.data.accountInfo.ctime
      ).substr(0, 10);
      this.obj = res.data.accountInfo;
    });
  },
};
</script>

<style lang="less" scoped>
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 480px;
}
.img {
  width: 200px;
  height: 200px;
  img {
    width: 100%;
    height: 100%;
  }
}
p {
  font-size: 14px;
  color: #606266;
  padding-right: 12px;
  text-align: right;
  width: 80px;
}
</style>